package top.codetheory._01_动态数组.leetcode;

/**
 * @author:
 * @since: 2023/10/26 15:22
 **/
public class _26_删除有序数组中的重复项 {

    public static int removeDuplicates(int[] nums) {

        int slow = 1;
        int fast = 1;
        while (fast < nums.length) {

            // 找不和slow相同的
            while (fast < nums.length && nums[fast] == nums[slow - 1]) {
                fast++;
            }
            if (fast < nums.length) {
                nums[slow++] = nums[fast++];
            }

        }

        return slow;

    }


    public static void main(String[] args) {
//        int[] nums = {1,1,1,1,1,2,2,3,3,4};
        int[] nums = {1,1};
        int j = removeDuplicates(nums);
        System.out.println(j);
        for (int i = 0; i < j; i++) {
            System.out.println(nums[i]);
        }

    }
}